<?php
class Notes {
	
	public function add_note($student_id,$title,$text) // dodaje nauczyciela do bazy
    {
		$database = Database::getInstance();
		$register_query = $database->dbh->prepare("INSERT INTO notes (student_id,title,text) VALUES ('{$student_id}','{$title}','{$text}')");
		
		if($register_query->execute()){ 
			return 1; // zarejestrowano
		}else{
			return 0; // coś się nie udało
		}
    }
	
	public function get_notes()
	{
		$database = Database::getInstance();
		$get_query = $database->dbh->prepare("SELECT id,student_id,title,text,added FROM notes ORDER BY added DESC");
		$get_query->execute();
		$result = $get_query->fetchAll();
		foreach($result as $id => $note) {
			$noteData[$id]['id'] = $note['id'];
			$noteData[$id]['student_id'] = $note['student_id'];
			$noteData[$id]['title'] = $note['text'];
			$noteData[$id]['text'] = $note['text'];
			$noteData[$id]['added'] = $note['added'];
        }
		return $noteData;
	}
	
	public function get_student($id)
	{
		$database = Database::getInstance();
		$get_query = $database->dbh->prepare("SELECT firstName,lastName FROM student WHERE id = $id");
		$get_query->execute();
		$result = $get_query->fetchAll();
		foreach($result as $data) {
			$studentData['firstName'] = $data['firstName'];
			$studentData['lastName'] = $data['lastName'];
        }
		
		$student = sprintf("%s %s",$studentData['firstName'],$studentData['lastName']);
		return $student;
	
	}
} 

?>